﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
    <title>项目列表</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageStyles" runat="server">
    <link href="../../Content/project/project.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .txt-projectname
        {
            font-size: 20px;
            font-weight: bold;
            color: #323232;
        }
        .txt-projectExplanation
        {
            font-size: 14px;
            color: #666;
        }
        
        .div-endDate
        {
            right: 10px;
            position: absolute;
            display: inline;
        }
        
        .txt-workitem-finished
        {
            background: #3ba365;
        }
        
        .txt-workitem-expired
        {
            background: #e8465f;
        }
        .txt-workitem-unfinished
        {
            background: #999999;
        }
        
        .txt-leader
        {
            color: #666;
            font-size: 14px;
            margin-top: 10px;
        }
        .resend_recover
        {
            border: 1px solid #CCCCCC;
            margin-bottom: 15px;
            margin-top: 10px;
            padding: 10px;
        }
        .div-workitem
        {
            width: 14px;
            height: 100%;
            border-radius: 4px 0px 0px 4px;
            -webkit-transition: border 0.3s ease;
            position: absolute;
        }
        .div-project
        {
            background-color: #f5f5f5;
            overflow: hidden;
            border: 1px solid #A8A8A8;
            margin: 5px 0 0 0;
            -webkit-border-radius: 4px;
            border-radius: 4px;
            -webkit-box-shadow: 2px 2px 5px #aaa;
            box-shadow: 2px 2px 5px #aaa;
            display: block;
            position: relative;
        }
        .div-project:hover
        {
            cursor: pointer;
        }
        .div-project-info
        {
            float: left;
            margin: 10px 80px 10px 30px;
            min-height: 100px;
        }
        .div-project:hover
        {
            background: #dedede;
        }
        .fieldslist input
        {
            width: 240px;
        }
        .popup-block
        {
            z-index: 50;
        }
        #overlay
        {
            z-index: 49;
        }
        .contextPanelCover
        {
            background-color: transparent;
        }
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageScripts" runat="server">
    <script type="text/javascript">
       
        //************* 全局变量

        var g_Var = {
            'tempUserId': null,
            'projectList': null,
        };

        var ProjectStatusValue = {
            Ongoing: 1,
            Archive: 2
        };


    //************* Accessor访问器
    var EzAccessor = {};
        
    function CreateAccessor() {
        if (ezmock.IS_MOCKED) {
            EzAccessor = CreateMockEzAccessor();

        } else {
            EzAccessor = CreateRealEzAccessor();
        }
    }


    function CreateMockEzAccessor() {
        //模拟实现服务器交互方法

        var mockEzAccessor = {

    };

    return mockEzAccessor;
}

function CreateRealEzAccessor() {
    //实现服务器交互方法
    var realEzAccessor = {
        "getHasCreateProjectPermission": function () { 
            return <%= WebJsonExtension.ToJson(Model.HasCreateProjectPermission) %>;
        }
    };

return realEzAccessor;
}


function bindProjectInfo(projectList){
    $('.div-project-list').empty();

    if (projectList.length == 0) {
        $('.div-project-list').append($('<p class="no-items">还没有项目</p>'));  
        return;  
    }

    for( var key in projectList){
        var rootDom = $("#projectInfo").tmpl(projectList[key]).appendTo($('.div-project-list'));
        
        var totalCount = projectList[key].Workitem.UnfinishedCount + 
                         projectList[key].Workitem.FinishedCount + 
                         projectList[key].Workitem.ExpiredCount;
        
        if (totalCount > 0){
            $('#'+ projectList[key].Id)
                .find('.txt-workitem-finished')
                .height($('.div-workitem').height() * projectList[key].Workitem.FinishedCount / totalCount);
            $('#'+ projectList[key].Id)
                .find('.txt-workitem-expired')
                .height($('.div-workitem').height() * projectList[key].Workitem.ExpiredCount / totalCount);
            $('#'+ projectList[key].Id)
                .find('.txt-workitem-unfinished')
                .height($('.div-workitem').height() * (1- ( projectList[key].Workitem.FinishedCount + projectList[key].Workitem.ExpiredCount) / totalCount));
        }
    }

    $('.div-project').each(function (){
        var _self = $(this);
        _self.click(function() {
            window.location.href = "/project/projectInfo?id=" + _self.attr('id');
        });
    });   

};

//function getLeaderDom(leader){
//    var leaderDom = $('<div class="div-leader-list"/>');
//    var leaderInfoStr = '<div class="div-leaderinfo">' + 
//                            '<img class="img-photo-leader" src="/core/headicon/{UserId}" alt="headicon" />' +
//                            '<p class="txtMember">{UserName}</p>' + 
//                        '</div>';
//    leaderInfoStr = leaderInfoStr.replace("{UserId}", leader.Member.Id)   
//                                 .replace("{UserName}",leader.Member.Name);
//    leaderDom.append(leaderInfoStr);   
//    
//    return leaderDom;
//}

//function getMemberListDom(memberList) {
//    var membersDom = $('<div class="div-member-list"/>');
//    var count = 0;
//    for (var key in memberList){
//        if(memberList[key].Role == "member"){
//            count++;
//            if (count <= 5) {
//                var memberInfoStr = '<div class="div-member">' +
//                        '<img class="img-photo-member" src="/core/headicon/{UserId}" alt="headicon" />' +
//                        '<p class="txtMember">{UserName}</p>';

//                memberInfoStr = memberInfoStr.replace("{UserId}", memberList[key].Member.Id)   
//                                             .replace("{UserName}", memberList[key].Member.Name);
//                membersDom.append(memberInfoStr);   
//            }
//        }
//    }
//    if (count > 5) {
//       membersDom.append('<div class="div-member"><p> ... <p></div>');
//    }
//    if (count == 0) {
//        return "";
//    }   

//    return  membersDom;
//} 

function setPageTitle (hasCreateProjectPermission) {
    if(hasCreateProjectPermission == true){
        $('.title').html('公司项目');
        $('.txt-pageRemind').html('您可以查看公司所有项目的详细信息,创建新的项目.');
    }else {
        $('.title').html('我的项目');
        $('.txt-pageRemind').html('您可以查看您参与的所有项目的详细信息.');
    }
}

//初始化页面
function initPage() {
    CreateAccessor();
    $('#tip_template').eztips();

    var hasCreateProjectPermission = EzAccessor.getHasCreateProjectPermission();
    setPageTitle(hasCreateProjectPermission);

    EzDesk.Service.GetAllFullProjects_Sync(function(e) {
        g_Var.projectList = e;
        bindOngoingProjects();
    });
}


function bindOngoingProjects(){
    var ongoingProjects = $.grep(g_Var.projectList, function(project){
        return project.StatusValue != ProjectStatusValue.Archive;
    });

    bindProjectInfo(ongoingProjects);
}

function bindAllProjects(){
    var allProjects = g_Var.projectList;

    bindProjectInfo(allProjects);
}


var DoCreateProject = function (callback) {
    $.AjaxBusy.show("创建中...");
    $('#content-add-project').find('.projcet-creator').ajaxSubmit({
        success: function (e) {
            callback(e);
        }
    });
    return
};

function initValidation() {
    $('#content-add-project').find('.projcet-creator').validate({
        rules:
            {
                projectName: {
                    required: true,
                },
                projectCode: {
                    required: true,
                }
            },
        messages:
            {
                projectName: {
                    required: "任务内容不能为空！"
                },
                projectCode: {
                    required: "任务编号不能为空！"
                }
            }
    });

};


//初始化事件
function initPageEvent() {
      
}

$(function () {
    initPage();
    initPageEvent();
});

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PageHead" runat="server">
    <%
        Html.RenderPartial("_sayHello"); %>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageContent" runat="server">
    <div id="page-head" class="page-head">
        <img src="../../Content/icons/projects_folder_badged.png" style="width: 48px; height: 48px;"
            alt="send" />
        <span class="title"></span>
    </div>
    <div id="page-body">
        <div class="resend_recover">
            <h3>
                我可以做些什么?</h3>
            <p style="font: 12px;" class="txt-pageRemind">
            </p>
        </div>
        <div id="radio">
            <input type="radio" id="project-ongoing" name="radio" checked="checked" /><label
                for="project-ongoing">进行中的项目</label>
            <input type="radio" id="project-all" name="radio" /><label for="project-all">所有项目</label>
        </div>
        <script>
            $(function () {
                $("#radio").buttonset();

                $("#radio").change(function () {
                    if ($('#project-ongoing').attr('checked')) {
                        bindOngoingProjects();
                    }
                    if ($('#project-all').attr('checked')) {
                        bindAllProjects();
                    }
                })

            });
        </script>
        <div class="div-project-list">
        </div>
        <div class="page-submit">
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="PageShortcut" runat="server">
    <div id="shortcuts" class="box">
        <%
            Html.RenderAction("_createProjectShortcut",
                              new { hasCreateProjectPermission = Model.HasCreateProjectPermission });
        %>
    </div>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="PageFoot" runat="server">
    <%--<div id="tip_template" style="display: none;">
        <%
            Html.RenderAction("_projectTemplates",
                          new { hasCreateProjectPermission = Model.HasCreateProjectPermission });
        %>
    </div>--%>
</asp:Content>
